home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / MacTutor Help Source / Code Resource Version / Pascal Example / main.p < prev    next >
Encoding:
Text File  |  1989-08-29  |  4.5 KB  |  187 lines  |  [TEXT/MPS ]

  1. {$S Main}
  2.  
  3. (* ------------------------------------------------- *)
  4. (*                   MAIN PROGRAM                    *)
  5. (* ------------------------------------------------- *)
  6. (* Purpose: Perform the routine initializations and  *)
  7. (*          enter the event loop.                    *)
  8. (* ------------------------------------------------- *)
  9.  
  10. PROGRAM  example;
  11.  
  12. USES
  13.     MemTypes,QuickDraw,OSIntf,ToolIntf,PackIntf,
  14.     Dispatcher;
  15.  
  16. VAR
  17.     myEvent             : EventRecord;
  18.     doneFlag             : boolean;
  19.     code                 : integer;
  20.     whichWindow         : WindowPtr;
  21.     tempRect,OldRect     : Rect;
  22.     mResult             : longint;
  23.     theMenu, theItem     : integer;
  24.     chCode                 : integer;
  25.     ch                     : char;
  26.     myPt                : Point;
  27.  
  28. BEGIN
  29.     MoreMasters;
  30.     MoreMasters;
  31.     MoreMasters;
  32.     MoreMasters;
  33.     InitGraf(@thePort);
  34.     InitFonts;
  35.     InitWindows;
  36.     InitMenus;
  37.     TEInit;
  38.     InitDialogs(nil);
  39.     FlushEvents ( everyEvent , 0 );
  40.     InitCursor;
  41.  
  42.     ClearMenuBar;                     
  43.     SetMenuBar(GetNewMBar (MBarID));
  44.     AddResMenu(GetMHandle (AppleID), 'DRVR');
  45.     DrawMenuBar;
  46.  
  47.     doneFlag := FALSE;
  48.  
  49.     REPEAT
  50.         SystemTask;
  51.  
  52.         IF GetNextEvent(everyEvent, myEvent) THEN
  53.             BEGIN
  54.                 code := FindWindow(myEvent.where, whichWindow);
  55.  
  56.                 CASE myEvent.what OF
  57.                     MouseDown :
  58.                     BEGIN
  59.                         IF (code = inMenuBar) then
  60.                         BEGIN
  61.                             mResult := MenuSelect(myEvent.Where);
  62.                             theMenu := HiWord(mResult);
  63.                             theItem := LoWord(mResult);
  64.                             Handle_My_Menu(doneFlag, theMenu, theItem);
  65.                         END;
  66.  
  67.                         IF (code = InDrag) then
  68.                         BEGIN
  69.                             tempRect := screenbits.bounds;
  70.                             SetRect(tempRect,tempRect.Left+10,tempRect.Top+25,tempRect.Right-10,tempRect.Bottom - 10);
  71.                             DragWindow(whichWindow, myEvent.where, tempRect);
  72.                         END;
  73.  
  74.                         IF ((code = inGrow) and (whichWindow <> nil)) then
  75.                         BEGIN
  76.                             SetPort(whichWindow);
  77.  
  78.                             myPt := myEvent.where;
  79.                             GlobalToLocal(myPt);
  80.  
  81.                             OldRect := WhichWindow^.portRect;
  82.  
  83.                             WITH screenbits.bounds DO
  84.                                 SetRect( tempRect, 15, 15, 
  85.                                         (right - left),  (bottom - top) - 20);
  86.                             mResult := GrowWindow(whichWindow,myEvent.where, tempRect);
  87.                             SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);
  88.                              SetPort(whichWindow);
  89.                              SetRect(tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15); 
  90.                             EraseRect(tempRect);
  91.                             InvalRect(tempRect);
  92.                             SetRect(tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);  
  93.                             EraseRect(tempRect);
  94.                             InvalRect(tempRect);
  95.                             DrawGrowIcon(whichWindow);
  96.                         END;
  97.  
  98.                         IF (code = inZoomIn) or (code = inZoomOut) then
  99.                         BEGIN
  100.                             IF (WhichWindow <> nil) then
  101.                             BEGIN
  102.                                 SetPort(whichWindow);
  103.                                 myPt := myEvent.where;
  104.                                 GlobalToLocal(myPt);
  105.                                 OldRect := whichWindow^.portRect;
  106.                                 IF TrackBox(whichWindow, myPt, code) then
  107.                                 BEGIN
  108.                                 ZoomWindow(WhichWindow, code, TRUE);
  109.                                 SetRect(tempRect, 0, 0, 32000, 32000);
  110.                                 EraseRect(tempRect);
  111.                                 InvalRect(tempRect);
  112.                                 END;
  113.                             END;
  114.                         END;
  115.  
  116.                         IF (code = inGoAway) then
  117.                         BEGIN
  118.                             If TrackGoAway(whichWindow,myEvent.where) then
  119.                             BEGIN
  120.                             END;
  121.                         END;
  122.  
  123.                         IF (code = inContent) then
  124.                         BEGIN
  125.                             IF (whichWindow <> FrontWindow) then
  126.                                 SelectWindow(whichWindow)
  127.                             else
  128.                             BEGIN
  129.                                 SetPort(whichWindow);
  130.                             END;
  131.                         END;
  132.  
  133.                         IF (code = inSysWindow) then
  134.                             SystemClick(myEvent, whichWindow);
  135.  
  136.                     END;
  137.  
  138.                     KeyDown,AutoKey:
  139.                     BEGIN
  140.                         with myevent do
  141.                         BEGIN
  142.                             chCode := BitAnd(message, CharCodeMask);
  143.                             ch := CHR(chCode);
  144.                             IF (Odd(modIFiers div CmdKey)) then
  145.                             BEGIN
  146.                                 mResult := MenuKey(ch);
  147.                                 theMenu := HiWord(mResult);
  148.                                 theItem := LoWord(mResult);
  149.                                 IF (theMenu <> 0) then
  150.                                     Handle_My_Menu(doneFlag, theMenu, theItem);
  151.                             END
  152.                         END;
  153.                     END;
  154.  
  155.                     UpDateEvt :
  156.                     BEGIN
  157.                         whichWindow := WindowPtr(myEvent.message);
  158.                         BeginUpdate(whichWindow);
  159.                         EndUpdate(whichWindow);
  160.                     END;
  161.  
  162.                     DiskEvt :
  163.                     BEGIN
  164.                         IF (HiWord(myevent.message) <> noErr) then
  165.                         BEGIN
  166.                             myEvent.where.h := ((screenbits.bounds.Right - screenbits.bounds.Left) div 2) - (304 div 2);
  167.                             myEvent.where.v := ((screenbits.bounds.Bottom - screenbits.bounds.Top) div 3) - (104 div 2);
  168.                             InitCursor;
  169.                             chCode := DIBadMount(myEvent.where, myevent.message);
  170.                         END;
  171.                      END;
  172.  
  173.                     ActivateEvt :
  174.                     BEGIN
  175.                         whichWindow := WindowPtr(myevent.message);
  176.                         IF odd(myEvent.modifiers) then
  177.                             BEGIN
  178.                                 SelectWindow(whichWindow);
  179.                             END;
  180.                     END;
  181.  
  182.                     otherwise;
  183.                  END;
  184.             END;
  185.         UNTIL doneFlag;
  186. END.
  187.